home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 255_01 / gpclip2.asm < prev    next >
Assembly Source File  |  1988-03-28  |  5KB  |  188 lines

  1.           page   80,132
  2.           page
  3. ;
  4. ;         Kent Cedola
  5. ;         2015 Meadow Lake Court
  6. ;         Norfolk, Virginia  23518
  7. ;
  8.  
  9. dgroup    group  _data
  10.  
  11. _data     segment word public 'data'
  12.           assume ds:dgroup
  13.  
  14.           extrn  _gdwd_x1:word,_gdwd_x2:word,_gdwd_x3:word
  15.           extrn  _gdwd_y1:word,_gdwd_y2:word,_gdwd_y3:word
  16.           extrn  _gdvw_x1:word,_gdvw_x2:word,_gdvw_x3:word
  17.           extrn  _gdvw_y1:word,_gdvw_y2:word,_gdvw_y3:word
  18.           extrn  _gdc_flg:byte
  19.  
  20. _data     ends
  21.  
  22. _text     segment byte public 'code'
  23.  
  24.           assume cs:_text,ds:dgroup
  25.           public _gpclip2
  26. _gpclip2  proc   near
  27.  
  28.           push   bp
  29.           mov    bp,sp
  30.  
  31.           push   si
  32.           push   di
  33.  
  34.           push   bp
  35.  
  36.           mov    di,[bp+4]
  37.           mov    cx,[di]               ; Load 'from' x coordinate of draw
  38.           mov    di,[bp+6]
  39.           mov    bx,[di]               ; Load 'from' y coordinate of draw
  40.           mov    di,[bp+8]
  41.           mov    si,[di]               ; Load 'to' x coordinate of draw
  42.           mov    di,[bp+10]
  43.           mov    di,[di]               ; Load 'to' y coordinate of draw
  44.  
  45.           mov    _gdc_flg,0
  46.  
  47. ;      Perform the Cohen-Sutherland two-step clipping algorithm, in which a
  48. ;  four-element code indicates the position of a point.  From pages 36-37 of
  49. ;  the book "Microcomputer Displays, Graphics, and Animation" by Bruce Atwick.
  50.  
  51. dline01:
  52.           XOR    AX,AX
  53.  
  54. ;      Generate 4-element start and end point codes
  55.  
  56.           CMP    BX,_gdwd_y1
  57.           JGE    $+5
  58.           OR     AH,8
  59.           CMP    BX,_gdwd_y2
  60.           JLE    $+5
  61.           OR     AH,4
  62.           CMP    CX,_gdwd_x1
  63.           JGE    $+5
  64.           OR     AH,2
  65.           CMP    CX,_gdwd_x2
  66.           JLE    $+5
  67.           OR     AH,1
  68.  
  69.           CMP    DI,_gdwd_y1
  70.           JGE    $+4
  71.           OR     AL,8
  72.           CMP    DI,_gdwd_y2
  73.           JLE    $+4
  74.           OR     AL,4
  75.           CMP    SI,_gdwd_x1
  76.           JGE    $+4
  77.           OR     AL,2
  78.           CMP    SI,_gdwd_x2
  79.           JLE    $+4
  80.           OR     AL,1
  81.  
  82.           OR     AX,AX
  83.           JNZ    dline15
  84.           JMP    dline09
  85. dline15:
  86.           mov    _gdc_flg,1
  87.           TEST   AH,AL
  88.           JZ     dline02
  89.           mov    _gdc_flg,2
  90.           pop    bp
  91.           jmp    done
  92. dline02:
  93.           OR     AL,AL
  94.           JNZ    dline03
  95.  
  96. ;      Swap start and end points
  97.  
  98.           XCHG   CX,SI                 ;
  99.           XCHG   BX,DI                 ;
  100.           XCHG   AH,AL
  101.  
  102. dline03:
  103.  
  104.           TEST   AL,2
  105.           JNZ    dline06
  106.           TEST   AL,4
  107.           JNZ    dline07
  108.           TEST   AL,8
  109.           JNZ    dline08
  110. dline05:
  111.           MOV    BP,DI
  112.           SUB    BP,BX
  113.           MOV    AX,_gdwd_x2
  114.           SUB    AX,CX
  115.           IMUL   BP
  116.           MOV    BP,SI
  117.           SUB    BP,CX
  118.           IDIV   BP
  119.           ADD    AX,BX
  120.           MOV    SI,_gdwd_x2
  121.           MOV    DI,AX
  122.           JMP    dline01
  123. dline06:
  124.           MOV    BP,DI
  125.           SUB    BP,BX
  126.           MOV    AX,_gdwd_x1
  127.           SUB    AX,CX
  128.           IMUL   BP
  129.           MOV    BP,SI
  130.           SUB    BP,CX
  131.           IDIV   BP
  132.           ADD    AX,BX
  133.           MOV    SI,_gdwd_x1
  134.           MOV    DI,AX
  135.           JMP    dline01
  136. dline07:
  137.           MOV    BP,SI
  138.           SUB    BP,CX
  139.           MOV    AX,_gdwd_y2
  140.           SUB    AX,BX
  141.           IMUL   BP
  142.           MOV    BP,DI
  143.           SUB    BP,BX
  144.           IDIV   BP
  145.           ADD    AX,CX
  146.           MOV    SI,AX
  147.           MOV    DI,_gdwd_y2
  148.           JMP    dline01
  149. dline08:
  150.           MOV    BP,SI
  151.           SUB    BP,CX
  152.           MOV    AX,_gdwd_y1
  153.           SUB    AX,BX
  154.           IMUL   BP
  155.           MOV    BP,DI
  156.           SUB    BP,BX
  157.           IDIV   BP
  158.           ADD    AX,CX
  159.           MOV    SI,AX
  160.           MOV    DI,_gdwd_y1
  161.           JMP    dline01
  162. dline09:
  163.           pop    bp
  164.  
  165.           mov    ax,di
  166.           mov    di,[bp+4]
  167.           mov    [di],cx               ; Store 'from' x coordinate of draw
  168.           mov    di,[bp+6]
  169.           mov    [di],bx               ; Store 'from' y coordinate of draw
  170.           mov    di,[bp+8]
  171.           mov    [di],si               ; Store 'to' x coordinate of draw
  172.           mov    di,[bp+10]
  173.           mov    [di],ax               ; Store 'to' y coordinate of draw
  174. done:
  175.  
  176.           mov    al,_gdc_flg
  177.           xor    ah,ah
  178.  
  179.           pop    di
  180.           pop    si
  181.  
  182.           pop    bp
  183.           ret
  184.  
  185. _gpclip2  endp
  186. _text     ends
  187.           end
  188.